package com.xja.contorller;

import com.xja.entity.Users;
import com.xja.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.jws.soap.SOAPBinding;
import java.util.Map;

@Controller
@RequestMapping("users")
@SessionAttributes({"loginuser","msg"})
public class UsersContorller {
    @Autowired
    private UsersService usersService;
    @RequestMapping("loginuser")
    public String loginuser(String name, String password, Map map){
        Users loginuser =usersService.username(name);
        System.out.println("loginuser"+loginuser);
        if (loginuser==null){
            map.put("msg","用户名不存在");
            return "redirect:/page/login.jsp";
        }
        if (!loginuser.getPassword().equals(password)){
            map.put("msg","密码错误");
            return "redirect:/page/login.jsp";
        }
        map.put("loginuser",loginuser);
        return "redirect:/house/findhouse.do";
    }

    @RequestMapping("reg")
    public String reg(Users user){
        usersService.reg(user);
        return "redirect:/page/regs.jsp";
    }
}
